package com.junjie.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class DBUtil {
	static{
		try {
			Class.forName(ConfigUtil.getValue("DRIVER"));
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
	}
	public static Connection getConnection() throws SQLException{
		Connection conn = null;
		conn = DriverManager.getConnection(ConfigUtil.getValue("URL"),ConfigUtil.getValue("USER"),ConfigUtil.getValue("PWD"));
		return conn;
	}
	public static void close(ResultSet rs,Statement st,Connection conn) throws SQLException{
		if(rs != null){
			rs.close();
			rs = null;
		}else if(st != null){
			st.close();
			st = null;
		}else if(conn != null){
			conn.close();
			conn = null;
		}
	}
	public static void close(Statement st,Connection conn) throws SQLException{
		if(st != null){
			st.close();
			st = null;
		}else if(conn != null){
			conn.close();
			conn = null;
		}
	}
	public static void main(String[] args) {
		try {
			System.out.println(getConnection());
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
}
